package view;
import java.awt.Label;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;

/**
 * The Class ViewDailyPhotosGUI.
 * @author Dmitry
 */
public class ViewDailyPhotosGUI extends AbstractGUI {
	
	/** The lbl please choosefrom. */
	private JLabel lblPleaseChoosefrom = null;
	
	/** The lbl from. */
	private JLabel lblFrom = null;
	
	/** The lbl to. */
	private JLabel lblTo = null;
	
	/** The btn ok. */
	private JButton btnOk = null;
	
	/** The from day spinner. */
	private JSpinner fromDaySpinner = null;
	
	/** The from month spinner. */
	private JSpinner fromMonthSpinner = null;
	
	/** The from year spinner. */
	private JSpinner fromYearSpinner = null;
	
	/** The from hour spinner. */
	private JSpinner fromHourSpinner = null;
	
	/** The from minute spinner. */
	private JSpinner fromMinuteSpinner = null;
	
	/** The from second spinner. */
	private JSpinner fromSecondSpinner = null;
	
	/** The to day spinner. */
	private JSpinner toDaySpinner = null;
	
	/** The to month spinner. */
	private JSpinner toMonthSpinner = null;
	
	/** The to year spinner. */
	private JSpinner toYearSpinner = null;
	
	/** The to hour spinner. */
	private JSpinner toHourSpinner = null;
	
	/** The to minute spinner. */
	private JSpinner toMinuteSpinner = null;
	
	/** The to second spinner. */
	private JSpinner toSecondSpinner = null;
	
	/** The lbl from day. */
	private JLabel lblFromDay = null;
	
	/** The lbl from month. */
	private JLabel lblFromMonth = null;
	
	/** The lbl from year. */
	private JLabel lblFromYear = null;
	
	/** The lbl from hour. */
	private JLabel lblFromHour = null;
	
	/** The lbl from minute. */
	private JLabel lblFromMinute = null;
	
	/** The lbl from seconds. */
	private JLabel lblFromSeconds = null;
	
	/** The lbl to day. */
	private JLabel lblToDay = null;
	
	/** The lbl to month. */
	private JLabel lblToMonth = null;
	
	/** The lbl to year. */
	private JLabel lblToYear = null;
	
	/** The lbl to hour. */
	private JLabel lblToHour = null;
	
	/** The lbl to minute. */
	private JLabel lblToMinute = null;
	
	/** The lbl to second. */
	private JLabel lblToSecond = null;
	
	/** The from slash. */
	private Label fromSlash = null;
	
	/** The from slash2. */
	private Label fromSlash2 = null;
	
	/** The from slash3. */
	private Label fromSlash3 = null;
	
	/** The from slash4. */
	private Label fromSlash4 = null;
	
	/** The to slash. */
	private Label toSlash = null;
	
	/** The year strings. */
	private String[] yearStrings = {"2011","2012","2013","2014"};
	
	/** The month strings. */
	private String[] monthStrings;
	
	/** The day strings. */
	private String[] dayStrings;
	
	/** The hour strings. */
	private String[] hourStrings;
	
	/** The min strings. */
	private String[] minStrings;
	
	/** The sec strings. */
	private String[] secStrings;	
	
	/** The from year model. */
	private SpinnerListModel fromYearModel;
	
	/** The from month model. */
	private SpinnerListModel fromMonthModel;
	
	/** The from day model. */
	private SpinnerListModel fromDayModel;
	
	/** The from hour model. */
	private SpinnerListModel fromHourModel;
	
	/** The from min model. */
	private SpinnerListModel fromMinModel;
	
	/** The from sec model. */
	private SpinnerListModel fromSecModel;
	
	/** The to year model. */
	private SpinnerListModel toYearModel;
	
	/** The to month model. */
	private SpinnerListModel toMonthModel;
	
	/** The to day model. */
	private SpinnerListModel toDayModel;
	
	/** The to hour model. */
	private SpinnerListModel toHourModel;
	
	/** The to min model. */
	private SpinnerListModel toMinModel;
	
	/** The to sec model. */
	private SpinnerListModel toSecModel;
	
	/**
	 * Instantiates a new view daily photos GUI.
	 */
	public ViewDailyPhotosGUI() {
		
		fromYearModel = new SpinnerListModel(yearStrings);
		toYearModel = new SpinnerListModel(yearStrings);
		
		monthStrings = createTimeStrings(12);
		fromMonthModel = new SpinnerListModel(monthStrings);
		toMonthModel = new SpinnerListModel(monthStrings);
		
		dayStrings = createTimeStrings(31);
		fromDayModel = new SpinnerListModel(dayStrings);
		toDayModel = new SpinnerListModel(dayStrings);
		
		hourStrings = createTimeStrings(24);
		hourStrings[23] = "00";
		fromHourModel = new SpinnerListModel(hourStrings);
		toHourModel = new SpinnerListModel(hourStrings);
		
		minStrings = createTimeStrings(60);
		minStrings[59] = "00";
		fromMinModel = new SpinnerListModel(minStrings);
		toMinModel = new SpinnerListModel(minStrings);
		
		secStrings = createTimeStrings(60);
		secStrings[59] = "00";
		fromSecModel = new SpinnerListModel(secStrings);
		toSecModel = new SpinnerListModel(secStrings);
		
		getContentPane().setLayout(null);
		getContentPane().add(getLblPleaseChooseFrom());
		getContentPane().add(getLblFrom());
		getContentPane().add(getLblTo());
		getContentPane().add(getOkButton());
		getContentPane().add(getBackButton());
		getContentPane().add(getFromMonthSpinner());
		getContentPane().add(getFromDaySpinner());
		getContentPane().add(getFromYearSpinner());
		getContentPane().add(getToDaySpinner());
		getContentPane().add(getToMonthSpinner());
		getContentPane().add(getToYearSpinner());
		getContentPane().add(getLblFromDay());
		getContentPane().add(getLblFromMonth());
		getContentPane().add(getLblFromYear());
		getContentPane().add(getLblToDay());
		getContentPane().add(getLblToMonth());
		getContentPane().add(getLblToYear());
		getContentPane().add(getFromSlash());
		getContentPane().add(getFromSlash2());
		getContentPane().add(getToSlash());
		getContentPane().add(getToSlash2());
		getContentPane().add(getFromMinuteSpinner());
		getContentPane().add(getFromHourSpinner());
		getContentPane().add(getFromSecondSpinner());
		getContentPane().add(getToHourSpinner());
		getContentPane().add(getToMinuteSpinner());
		getContentPane().add(getToSecondSpinner());
		getContentPane().add(getLblFromHour());
		getContentPane().add(getLblFromMinute());
		getContentPane().add(getLblFromSeconds());
		getContentPane().add(getLblToHour());
		getContentPane().add(getLblToMinute());
		getContentPane().add(getToSecondSpinner());
		getContentPane().add(getFromSlash4());
		getContentPane().add(getToSlash3());
		getContentPane().add(getToSlash4());
		getContentPane().add(getLblToSeconds());
		
		this.setTitle("View Daily Photos");
		this.setBounds(200, 200, 452, 381);
		this.setVisible(true);
		this.setResizable(false);
	}

	/**
	 * Gets the lbl please choosefrom.
	 *
	 * @return the lbl please choosefrom
	 */
	public JLabel getLblPleaseChoosefrom() {
		return lblPleaseChoosefrom;
	}

	/**
	 * Gets the from day spinner.
	 *
	 * @return the from day spinner
	 */
	private JSpinner getFromDaySpinner() {
		if(fromDaySpinner == null){
			fromDaySpinner = new JSpinner(fromDayModel);
			fromDaySpinner.setBounds(10, 122, 52, 20);
		}
		return fromDaySpinner;
	}

	/**
	 * Gets the from month spinner.
	 *
	 * @return the from month spinner
	 */
	private JSpinner getFromMonthSpinner() {
		if(fromMonthSpinner == null){
			fromMonthSpinner = new JSpinner(fromMonthModel);
			fromMonthSpinner.setBounds(72, 122, 52, 20);
		}
		return fromMonthSpinner;
	}

	/**
	 * Gets the from year spinner.
	 *
	 * @return the from year spinner
	 */
	private JSpinner getFromYearSpinner() {
		if(fromYearSpinner == null){
			fromYearSpinner = new JSpinner(fromYearModel);
			fromYearSpinner.setBounds(134, 122, 52, 20);
		}
		return fromYearSpinner;
	}

	/**
	 * Gets the from hour spinner.
	 *
	 * @return the from hour spinner
	 */
	private JSpinner getFromHourSpinner() {
		if(fromHourSpinner == null){
			fromHourSpinner = new JSpinner(fromHourModel);
			fromHourSpinner.setBounds(10, 167, 52, 20);
		}
		return fromHourSpinner;
	}

	/**
	 * Gets the from minute spinner.
	 *
	 * @return the from minute spinner
	 */
	private JSpinner getFromMinuteSpinner() {
		if(fromMinuteSpinner == null){
			fromMinuteSpinner = new JSpinner(fromMinModel);
			fromMinuteSpinner.setBounds(72, 167, 52, 20);
		}
		return fromMinuteSpinner;
	}

	/**
	 * Gets the from second spinner.
	 *
	 * @return the from second spinner
	 */
	private JSpinner getFromSecondSpinner() {
		if(fromSecondSpinner == null){
			fromSecondSpinner = new JSpinner(fromSecModel);
			fromSecondSpinner.setBounds(134, 167, 52, 20);
		}
		return fromSecondSpinner;
	}

	/**
	 * Gets the to day spinner.
	 *
	 * @return the to day spinner
	 */
	private JSpinner getToDaySpinner() {
		if(toDaySpinner == null){
			toDaySpinner = new JSpinner(toDayModel);
			toDaySpinner.setBounds(228, 122, 52, 20);
		}
		return toDaySpinner;
	}

	/**
	 * Gets the to month spinner.
	 *
	 * @return the to month spinner
	 */
	private JSpinner getToMonthSpinner() {
		if(toMonthSpinner == null){
			toMonthSpinner = new JSpinner(toMonthModel);
			toMonthSpinner.setBounds(290, 122, 52, 20);
		}
		return toMonthSpinner;
	}

	/**
	 * Gets the to year spinner.
	 *
	 * @return the to year spinner
	 */
	private JSpinner getToYearSpinner() {
		if(toYearSpinner == null){
			toYearSpinner = new JSpinner(toYearModel);
			toYearSpinner.setBounds(352, 122, 52, 20);
		}
		return toYearSpinner;
	}

	/**
	 * Gets the to hour spinner.
	 *
	 * @return the to hour spinner
	 */
	private JSpinner getToHourSpinner() {
		if(toHourSpinner == null){
			toHourSpinner = new JSpinner(toHourModel);
			toHourSpinner.setBounds(228, 167, 52, 20);
		}
		return toHourSpinner;
	}

	/**
	 * Gets the to minute spinner.
	 *
	 * @return the to minute spinner
	 */
	private JSpinner getToMinuteSpinner() {
		if(toMinuteSpinner == null){
			toMinuteSpinner = new JSpinner(toMinModel);
			toMinuteSpinner.setBounds(290, 167, 52, 20);
		}
		return toMinuteSpinner;
	}

	/**
	 * Gets the to second spinner.
	 *
	 * @return the to second spinner
	 */
	private JSpinner getToSecondSpinner() {
		if(toSecondSpinner == null){
			toSecondSpinner = new JSpinner(toSecModel);
			toSecondSpinner.setBounds(352, 167, 52, 20);	
		}
		return toSecondSpinner;
	}

	/**
	 * Gets the lbl from day.
	 *
	 * @return the lbl from day
	 */
	private JLabel getLblFromDay() {
		if(lblFromDay == null){
			lblFromDay = new JLabel("Day");
			lblFromDay.setBounds(10, 109, 46, 14);
		}
		return lblFromDay;
	}

	/**
	 * Gets the lbl from month.
	 *
	 * @return the lbl from month
	 */
	private JLabel getLblFromMonth() {
		if(lblFromMonth == null){
			lblFromMonth = new JLabel("Month");
			lblFromMonth.setBounds(72, 109, 46, 14);
		}
		return lblFromMonth;
	}

	/**
	 * Gets the lbl from year.
	 *
	 * @return the lbl from year
	 */
	private JLabel getLblFromYear() {
		if(lblFromYear == null){
			lblFromYear = new JLabel("Year");
			lblFromYear.setBounds(134, 109, 46, 14);
		}
		return lblFromYear;
	}

	/**
	 * Gets the lbl from hour.
	 *
	 * @return the lbl from hour
	 */
	private JLabel getLblFromHour() {
		if(lblFromHour == null){
			lblFromHour = new JLabel("Hour");
			lblFromHour.setBounds(10, 154, 52, 14);
		}
		return lblFromHour;
	}

	/**
	 * Gets the lbl from minute.
	 *
	 * @return the lbl from minute
	 */
	private JLabel getLblFromMinute() {
		if(lblFromMinute == null){
			lblFromMinute = new JLabel("Minutes");
			lblFromMinute.setBounds(72, 154, 52, 14);
		}
		return lblFromMinute;
	}

	/**
	 * Gets the lbl from seconds.
	 *
	 * @return the lbl from seconds
	 */
	private JLabel getLblFromSeconds() {
		if(lblFromSeconds == null){
			 lblFromSeconds = new JLabel("Seconds");
				lblFromSeconds.setBounds(134, 154, 52, 14);
		}
		return lblFromSeconds;
	}

	/**
	 * Gets the lbl to month.
	 *
	 * @return the lbl to month
	 */
	private JLabel getLblToMonth() {
		if(lblToMonth == null){
			lblToMonth = new JLabel("Month");
			lblToMonth.setBounds(290, 109, 46, 14);	
		}
		return lblToMonth;
	}

	/**
	 * Gets the lbl to year.
	 *
	 * @return the lbl to year
	 */
	private JLabel getLblToYear() {
		if(lblToYear == null){
			lblToYear = new JLabel("Year");
			lblToYear.setBounds(352, 109, 46, 14);
		}
		return lblToYear;
	}

	/**
	 * Gets the lbl to hour.
	 *
	 * @return the lbl to hour
	 */
	private JLabel getLblToHour() {
		if(lblToHour == null){
			lblToHour = new JLabel("Hour");
			lblToHour.setBounds(228, 153, 46, 14);
		}
		return lblToHour;
	}

	/**
	 * Gets the lbl to minute.
	 *
	 * @return the lbl to minute
	 */
	private JLabel getLblToMinute() {
		if(lblToMinute == null){
			lblToMinute = new JLabel("Minutes");
			lblToMinute.setBounds(290, 154, 46, 14);
		}
		return lblToMinute;
	}

	/**
	 * Gets the lbl to second.
	 *
	 * @return the lbl to second
	 */
	private JLabel getLblToSecond() {
		if(lblToSecond == null){
			lblToSecond = new JLabel("Seconds");
			lblToSecond.setBounds(352, 125, 46, 14);
		}
		return lblToSecond;
	}

	/**
	 * Gets the from slash.
	 *
	 * @return the from slash
	 */
	private Label getFromSlash() {
		if(fromSlash == null){
			fromSlash = new Label("/");
			fromSlash.setBounds(64, 122, 8, 19);
		}
		return fromSlash;
	}

	/**
	 * Gets the from slash2.
	 *
	 * @return the from slash2
	 */
	private Label getFromSlash2() {
		if(fromSlash2 == null){
			fromSlash2 = new Label("/");
			fromSlash2.setBounds(124, 122, 8, 19);
		}
		return fromSlash2;
	}

	/**
	 * Gets the from slash3.
	 *
	 * @return the from slash3
	 */
	private Label getFromSlash3() {
		if(fromSlash3 == null){
			fromSlash3 = new Label("/");
			fromSlash3.setBounds(64, 138, 8, 19);
			getContentPane().add(fromSlash3);
		}
		return fromSlash3;
	}

	/**
	 * Gets the from slash4.
	 *
	 * @return the from slash4
	 */
	private Label getFromSlash4() {
		if(fromSlash4 == null){
			fromSlash4 = new Label("/");
			fromSlash4.setBounds(124, 167, 8, 19);	
		}
		return fromSlash4;
	}

	/**
	 * Gets the to slash.
	 *
	 * @return the to slash
	 */
	private Label getToSlash() {
		if(toSlash == null){
			toSlash = new Label("/");
			toSlash.setBounds(282, 122, 8, 19);	
		}
		return toSlash;
	}

	/**
	 * Gets the to slash2.
	 *
	 * @return the to slash2
	 */
	private Label getToSlash2() {
		if(toSlash2 == null){
			toSlash2 = new Label("/");
			toSlash2.setBounds(343, 122, 8, 19);
		}
		return toSlash2;
	}

	/**
	 * Gets the to slash3.
	 *
	 * @return the to slash3
	 */
	private Label getToSlash3() {
		if(toSlash3 == null){
			toSlash3 = new Label("/");
			toSlash3.setBounds(282, 167, 8, 19);
		}
		return toSlash3;
	}

	/**
	 * Gets the to slash4.
	 *
	 * @return the to slash4
	 */
	private Label getToSlash4() {
		if(toSlash4 == null){
			toSlash4 = new Label("/");
			toSlash4.setBounds(343, 167, 8, 19);
		}
		return toSlash4;
	}
	
	/**
	 * Gets the lbl to day.
	 *
	 * @return the lbl to day
	 */
	private JLabel getLblToDay(){
		if(lblToDay == null){
			lblToDay = new JLabel("Day");
			lblToDay.setBounds(228, 108, 46, 14);
		}
		return lblToDay;
	}
	
	/** The to slash2. */
	private Label toSlash2 = null;
	
	/** The to slash3. */
	private Label toSlash3 = null;
	
	/** The to slash4. */
	private Label toSlash4 = null;
	
	/** The lbl to seconds. */
	private JLabel lblToSeconds;
	
	
		
	
	/**
	 * Gets the lbl please choose from.
	 *
	 * @return the lbl please choose from
	 */
	private JLabel getLblPleaseChooseFrom(){
		if(lblPleaseChoosefrom == null){
			lblPleaseChoosefrom = new JLabel("<html><body>Please choose \"From\" date and \"To\" date in order to view "
					+ "the <br> photos from requested dates.</html></body>");
			lblPleaseChoosefrom.setBounds(10, 11, 426, 47);
		}
		return lblPleaseChoosefrom;
	}
	
	/**
	 * Gets the lbl from.
	 *
	 * @return the lbl from
	 */
	private JLabel getLblFrom() {
		if(lblFrom == null){
			lblFrom = new JLabel("From");
			lblFrom.setBounds(10, 87, 46, 14);
		}
		return lblFrom;
	}
	
	/**
	 * Gets the lbl to.
	 *
	 * @return the lbl to
	 */
	private JLabel getLblTo() {
		if(lblTo == null){
			lblTo = new JLabel("To");
			lblTo.setBounds(228, 87, 46, 14);
		}
		return lblTo;
	}
	
	/**
	 * Gets the ok button.
	 *
	 * @return the ok button
	 */
	private JButton getOkButton() {
		if(btnOk == null){
			btnOk = new JButton("OK");
			btnOk.setBounds(97, 307, 89, 23);
		}
		return btnOk;
	}
	
	/**
	 * Gets the back button.
	 *
	 * @return the back button
	 */
	private JButton getBackButton() {
		if(backButton == null){
			backButton = new JButton("Back");
			backButton.setBounds(228, 307, 89, 23);
		}
		return backButton;
	}
	
	/**
	 * Gets the lbl to seconds.
	 *
	 * @return the lbl to seconds
	 */
	private JLabel getLblToSeconds() {
		if (lblToSeconds == null) {
			lblToSeconds = new JLabel("Seconds");
			lblToSeconds.setBounds(352, 153, 52, 14);
		}
		return lblToSeconds;
	}
	
	/**
	 * Adds the start button listener.
	 *
	 * @param listener the listener
	 */
	public void addStartButtonListener(ActionListener listener){
		getOkButton().addActionListener(listener);
	}
	
	/**
	 * Gets the from time stamp.
	 *
	 * @return the from time stamp
	 */
	public String getFromTimestamp()
	{
		String yyyy = (String) getFromYearSpinner().getValue();
		String MM = (String) getFromMonthSpinner().getValue();
		String dd = (String) getFromDaySpinner().getValue();
		String HH = (String) getFromHourSpinner().getValue();
		String mm = (String) getFromMinuteSpinner().getValue();
		String ss = (String) getFromSecondSpinner().getValue();
		
		// set the from time stamp format: "yyyy-MM-dd HH:mm:ss"
		String timeStamp = yyyy+"-"+MM+"-"+dd+" "+HH+":"+mm+":"+ss;
		return timeStamp;
	}
	
	/**
	 * Gets the to time stamp.
	 *
	 * @return the to time stamp
	 */
	public String getToTimestamp()
	{
		String yyyy = (String) getToYearSpinner().getValue();
		String MM = (String) getToMonthSpinner().getValue();
		String dd = (String) getToDaySpinner().getValue();
		String HH = (String) getToHourSpinner().getValue();
		String mm = (String) getToMinuteSpinner().getValue();
		String ss = (String) getToSecondSpinner().getValue();
		
		// set the to time stamp format: "yyyy-MM-dd HH:mm:ss"
		String timeStamp = yyyy+"-"+MM+"-"+dd+" "+HH+":"+mm+":"+ss;
		return timeStamp;
	}
	
	/**
	 * Creates the time strings for the spinners.
	 *
	 * @param limit the limit of the string
	 * @return the string[] which contains the numbers for the requested spinner.
	 */
	private String[] createTimeStrings(int limit)
	{
		String [] res = new String[limit];
		for (int i = 0; i < limit; i++) 
		{
			res[i] = (i<9 ? "0":"") + (i+1);
		}
		
		return res;
	}
	
}
